<?php

class BookLanguagesController  extends Zend_Controller_Action{
    public function init(){

    }

    public function indexAction(){
        $bookLanguagesPaginator = Application_Model_BookLanguages::getInstance()->getPaginator();
        $bookLanguagesPaginator ->setItemCountPerPage(12);
        $page = $this->getRequest()->getParam('page');
        if(!is_null($page)){
            $bookLanguagesPaginator->setCurrentPageNumber($page);
        }

        $this->view->bookLanguagesPaginator = $bookLanguagesPaginator;
    }

    public function addAction(){
        $formBookLanguage = new Application_Form_BookLanguage();
        $request = $this->getRequest();
        if($request->isPost()){
            if($formBookLanguage->isValid($request->getPost())){
                $bookValues = $formBookLanguage->getValues();
                Application_Model_BookLanguages::getInstance()->create($bookValues);
                $this->redirect($this->view->url(array('controller' => 'book-languages'), null, true));
            }
        }
        $this->view->formBookLanguage = $formBookLanguage;
    }
}